<?php
use common\extended\system\func;
use yii\bootstrap\ActiveForm;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\LinkPager;

?>
<div class="row">
    <div class="container lh30">
        <a class="topNav" href="<?=Url::toRoute('/system/site/index')?>" style=""><img src="<?=Yii::getAlias('@web/backend/img/home/home.png');?>" alt="首页"/>返回首页</a>
    </div>
</div>
<div class="row nav-brand-bg">
    <div class="container">

    <ul id="myTab" class="nav nav-tabs">
        <li><a href="<?=Url::toRoute(['config/list','type'=>1]) ?>" >充值卡</a></li>
        <li><a href="<?=Url::toRoute(['config/list','type'=>2]) ?>" >疗程卡</a></li>
        <li><a href="<?=Url::toRoute(['config/list','type'=>3]) ?>" >合作项目</a></li>
        <li><a href="<?=Url::toRoute(['config/list','type'=>4]) ?>" >服务项目</a></li>
        <li><a href="<?=Url::toRoute(['config/list','type'=>5]) ?>" >房间</a></li>
        <li class="active"><a href="<?=Url::toRoute(['config/list','type'=>6]) ?>" >库存</a></li>
    </ul>


    </div>
</div>
<div class="row borB mt10">
    <div class="container">
        <ul class="nav nav-tabs smNav">
            <li <?php if($cat == 1): ?> class="active"<?php endif?>><a href="<?=Url::toRoute(['config/list','type'=>6,'cat'=>1]) ?>">供应商</a></li>
            <li <?php if($cat == 2): ?> class="active"<?php endif?>><a href="<?=Url::toRoute(['config/list','type'=>6,'cat'=>2]) ?>">类别</a></li>
            <li <?php if($cat == 3): ?> class="active"<?php endif?>><a href="<?=Url::toRoute(['config/list','type'=>6,'cat'=>3]) ?>">品牌</a></li>
            <li <?php if($cat == 4): ?> class="active"<?php endif?>><a href="<?=Url::toRoute(['config/list','type'=>6,'cat'=>4]) ?>">系列</a></li>
            <li <?php if($cat == 5): ?> class="active"<?php endif?>><a href="<?=Url::toRoute(['config/list','type'=>6,'cat'=>5]) ?>">规格</a></li>
        </ul>
    </div>
</div>
    <div class="container">
             <a href="javascript:;" class="add-recharge btnBg mg20-y"><i class="fa fa-plus-circle" style="margin-right: 50px"></i>添加</a>

                <div class="table_kj table-responsive">
                    <?php if(empty($list)){?>
                    <table class="table table-bordered">
                        <thead>
                        <tr>
                            <th><?=func::getTitle($cat)?>   </th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr class="lastTr" style="display: none;">
                            <form id="test" method="post" role="form" action="<?=Url::toRoute('config/add')?>">
                                <input class="read" name="key" type="hidden" value="<?=func::getTitle($cat)?>"/>
                                <td><input class="read" name="val" type="text"/><input type="hidden" name="type" value="6" /><input type="hidden" name="cat" value="<?=$cat?>"></td>
                                <td><input name="_csrf" type="hidden" id="_csrf" value="<?= Yii::$app->request->csrfToken ?>">
                                    <input type="submit" value="保存" class="edit btn btn-sm btn-borB4" />
                                    <a href="#" class="edit restb btn btn-sm btn-borB4 ml20">取消</a></td>
                            </form>
                        </tr>
                        <tr class="lastSet">
                            <td colspan="3" align="center"><img src="<?=Yii::getAlias('@web/backend/img/nodata.gif');?>"></td>
                        </tr>
                        </tbody>
                    </table>
                    <?php }else{?>
                    <table class="table table-bordered" style="table-layout: fixed;">
                        <thead>
                        <tr>
                            <th><?=func::getTitle($cat)?>   </th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php foreach ($list as $r){?>
                        <tr>
                        	<?php ActiveForm::begin(['action'=>Url::toRoute('config/update')])?>
                            <input type="hidden" name="key" value="<?=func::getTitle($cat)?>" readonly/>
                            <td><input class="read-only cas" type="text" name="val" value="<?=Html::encode($r['config_val']) ?>" readonly/><input type="hidden" name="id" value="<?=$r['config_id']?>" /><input type="hidden" name="cat" value="<?=$cat?>"><input type='hidden' name='type' value='6' /></td>
                            <td>
                                <a href="#" class="editBtn btn btn-sm btn-borB4">编辑</a>
                                <div class="fadeBox" style="display: none; float: left;">
                                    <input type="submit" class="edit btn btn-sm btn-borB4 cet" value="保存" />
                                    <a href="#" class="edit rest btn btn-sm btn-borB4 ml20">取消</a>
                                    <a class="btn btn-sm btn-borB4 ml20" href="<?=Url::toRoute(['config/del','id'=>$r['config_id']]);?>">删除</a>
                                </div>
                            </td>
                            <?php ActiveForm::end();?>
                        </tr>
                        <?php }?>
                        <tr class="lastTr" style="display: none;">
	                        <form id="test" method="post" role="form" action="<?=Url::toRoute('config/add')?>">
		                        <input class="read" name="key" type="hidden" value="<?=func::getTitle($cat)?>"/>
		                        <td><input class="read" id="val1" name="val" type="text"/><input type="hidden" name="type" value="6" /><input type="hidden" name="cat" value="<?=$cat?>"></td>
		                        <td><input name="_csrf" type="hidden" id="_csrf" value="<?= Yii::$app->request->csrfToken ?>">
		                            <input type="submit" value="保存" onclick="return checkAddConfig()" class="edit btn btn-sm btn-borB4" />
                                    <a href="#" class="edit restb btn btn-sm btn-borB4 ml20">取消</a></td>
	                        </form>
                        </tr>
                        
                        </tbody></table>
                    <?php }?>
                    <div class="page">
                    <?=LinkPager::widget([
					    'pagination' => $page,
						'firstPageLabel' => '首页',
						'nextPageLabel' => '下一页',
						'prevPageLabel' => '上一页',
						'lastPageLabel' => '末页',
					    'hideOnSinglePage'=>true
					]); ?>
                    </div>
                </div>
    </div>

<?php $this->beginBlock('js_index_end') ?>
$(function(){
$('.table tr').dblclick(function(){
var $this = $(this);
$(this).addClass('current');
$(this).siblings().removeClass('current');
$this.find('input[type="text"]').removeClass('read-only').removeAttr('readonly');
$this.find('.fadeBox').show();
$this.find('.editBtn').hide()
})
$('.rest').click(function(){
$(this).parent().parent().parent().removeClass('current');
$(this).parent().hide();
$(this).parent().parent().find('.editBtn').show();
$(this).parent().parent().parent().find('input[type="text"]').addClass('read-only').attr('readonly',true);
})
$('.editBtn').click(function(){
$(this).hide();
$(this).next().show();
$(this).parent().parent().addClass('current');
$(this).parent().parent().siblings().removeClass('current');
$(this).parent().parent().find('input[type="text"]').removeClass('read-only').removeAttr('readonly');
})
$('.add-recharge').click(function(e){
$('.lastTr').addClass('current');
$('.lastTr').show();
$('.lastSet').hide();
})
$('.restb').click(function(){
$('.lastTr').hide();
$('.lastSet').show();
})
})
<?php $this->endBlock() ?>
<?php $this->registerJs($this->blocks['js_index_end'], $this::POS_END); ?>
<?php $this->registerJsFile("@web/system/config/config5.js", ['position' => $this::POS_END]); ?>
